package lesson15homework;

public class StudentGroup 
{
	String groupSubject;
	Student[] students;
	int freePlaces;
	int groupPlace = 0;

	StudentGroup()
	{
		students = new Student[5];
		this.freePlaces = 5;
	}
	
	StudentGroup(String subject)
	{
		this();
		this.groupSubject = subject;
		
	}
	
	void addStudent (Student s)
	{
		if(groupPlace < students.length)
		{
			if(students[groupPlace] == null && s.subject.equalsIgnoreCase(groupSubject))
			{
			students[groupPlace] = s;
			this.groupPlace++;
			this.freePlaces--;
			}
		}
		else
		{
			System.out.printf("There is not free places in the group! %n %n");
		}
	}
	
	void emptyGroup()
	{
		for(int i = 0; i < this.students.length; i++)
		{
			students[i] = null;
		}
		this.groupPlace = 0;
		this.freePlaces = 5;
	}
	
	void theBestStudent()
	{
		int bestStudentInd = 0 ;
		double bestGradeStore = 0;
		
		for(int i = 0; i < students.length; i++)
		{
			if(students[i].grade > bestGradeStore)
			{
				bestGradeStore = students[i].grade;
				bestStudentInd = i;
			}
		}
		System.out.printf("Best Student is %s he/she have %1.2f grade! %n %n", students[bestStudentInd].name, students[bestStudentInd].grade );
	}
	
	void printStudentsInGroup(StudentGroup gr)
	{
		for(int i = 0; i < students.length; i++)
		{
			printStudentInfo(i);
		}
		
	}
	
	void printStudentInfo(int i)
	{
		System.out.println("Name: " + students[i].name);
		System.out.println("Age: " + students[i].age);
		System.out.println("Subject: " + students[i].subject);
		System.out.println("Grade: " + students[i].grade);
		System.out.println("Year in college: " + students[i].yearInCollege);
		System.out.println("Is Degree!? " + students[i].isDegree);
		System.out.println("Money" + students[i].money);
		System.out.println();
	}
}